@extends('admin.base')
@section('title', '商品列表')
@section('content')
<div class="layui-card">
        <blockquote class="layui-elem-quote layui-quote-nm">
            规格名:{{$lists->kname}}
        </blockquote>
        
        <fieldset class="layui-elem-field"> 
            <div class="layui-field-box">
                @if(empty($results))
                    该规格还没有添加属性
                @else
                    @foreach($results as $result)
                        <p onclick="del('{{url('admin/attrval/del')}}','{{$result->id}}',this);"  class="{{$result->id}}" style="cursor: pointer;border:1px solid #333;background-color:#ddd;margin-left:10px;display:inline-block;padding:2px 4px;">   
                            {{$result->vname}}  <span style="color:red;"> X</span>
                        </p>
                    @endforeach
                @endif          
            </div>
        </fieldset>
        
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" method="post" action="{{url('admin/attrval/insert')}}" enctype="multipart/form-data">
                @csrf
                <input type="hidden" name="attr_key_id" value="{{$lists->id}}">
                <div class="layui-form-item">
                    <!-- <label class="layui-form-label">规格名</label> -->
                    <div class="layui-input-inline">
                        <input type="text" name="vname" required  lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入属性名">
                    </div>
                </div>
                <div class="layui-form-item">
                    <!-- <div class="layui-input-block"> -->
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    <!-- </div> -->
                </div>
            </form>
        </div>
    </div>
@endsection

@section('js')
<script type="text/javascript">

    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                ajax("{{url('admin/attrval/insert')}}",data.field,function(data){
                    layer.close();
                    layer.closeAll();
                    layer.msg(data.msg);
                    if(data.code == 1){
                        window.location.reload();
                    }
                });
            });
            return false;
        });
    });



    function del(url,id,his){
        layer.confirm('确定删除？', {
            icon: 3,
            title:'提示框',
            btn: ['确定','取消'] //按钮
        },function(){
            $.ajax({
                url:url,
                type:'post',
                dataType:'json',
                data:{id:id},
                success:function (res) {
                    layer.msg(res.data);
                    // layer.close(index);
                    if(res.code == 200){
                        $(his).hide();
                    }
                    

                }
            });
        });
    }

    // layui.use('form', function(){
    //     var form = layui.form;
    //     form.render();
    //     //监听提交
    //     form.on('submit(formDemo)', function(data){
    //         /*
    //         <!-- return post(data.form); -->
    //         <!-- layer.msg(JSON.stringify(data.field)); -->
    //         <!-- return false; -->
    //         */
    //         layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
    //             $(data.form).ajaxSubmit({
    //                 success: function(data){

    //                     console.log(data);
    //                     if(data.code == 200){
    //                         //layer.close(index);
    //                         //layer.closeAll();
    //                         layer.msg(data.data);
    //                         window.location.reload();                      
    //                     }else{
    //                         layer.msg(data.data);
    //                     }
    //                 },
    //                 error: function (){
    //                     //layer.close(index);
    //                     //layer.closeAll();
    //                     layer.msg("系统正忙");
    //                     refresh();
    //                 }
    //             });
    //         });
    //         return false;
    //     });
    // });
    
    
</script>
@endsection